<template>
  <div class="newpage">
    <div class="content">
      <el-form ref="form" :model="formInline" label-width="80px">
        <div class="topBox">
          <div class="first">
            <div class="collegeName">
              <span>学院名称:</span><br>&nbsp;&nbsp;
              <el-select v-model="formInline.colleageName"  placeholder="请选择">
                <el-option v-for="item in options" :key="item.index" :label="item.colleageName" :value="item.colleageId">
                </el-option>
              </el-select>
            </div>
            <div class="createTime">
              <span>创建时间:</span><br>
              <div class="block">
                 <el-form-item label="日期">
                         <el-date-picker
                            v-model="formInline.beginTime"
                            type="date"
                            placeholder="选择日期"
                            value-format="yyyy-MM-dd"
                            >
                        </el-date-picker>
                        -
                        <el-date-picker
                            v-model="formInline.endTime"
                            type="date"
                            placeholder="选择日期"
                            value-format="yyyy-MM-dd"
                            >
                        </el-date-picker>
                    </el-form-item>
              </div>
            </div>

          </div>
          <div class="second">
            <div class="collegeName">
              <span>所属区域:</span><br>
              <el-input  v-model="formInline.site" placeholder="请输入详细地址"></el-input>
            </div>
            <div class="createTime">
              <span>描述:</span><br>
              <el-input v-model="formInline.describeText" type="textarea"></el-input>
            </div>
          </div>
          <div class="plannedEnrollment">
            <span>计划招生人数:</span>
            <ul>
              <li v-for="(item, index) in formInline.admissionSchemeNumber" :key="index">
                <span class="number"></span>
    
            <div class="countInp">
              <el-select v-model="item.majorId"  placeholder="请选择专业">
                <el-option v-for="item in major"
                 :key="item.index" :label="item.majorName" :value="item.majorId">
                </el-option>
              </el-select>
                </div>
                <span class="counts">招生人数</span>
                <div class="countInp">
                  <el-input  v-model="item.studentNumber" placeholder=""></el-input>
                </div>
                <!-- <i class="el-icon-remove-outline" @click="del"></i> -->
              </li>
              <el-button icon="el-icon-plus" @click='addOut'>添加</el-button>
            </ul>
          </div>
        </div>
        <div class="btn">
          <el-button @click="out">取消</el-button>
          <el-button type="primary" @click="edit">确定</el-button>
        </div>

      </el-form>

    </div>
  </div>

</template>
<script>
import {
  majorListApi,
} from "@/api/basics/major";
import {
  getTableApi,
} from "@/api/basics/college.js"
import {recruitInfo,recruitEdit} from '@/api/recruitStudents/recruit.js'
export default {
  data() {
    return {
      formInline: {
        beginTime:'',
        endTime:'',
        site:'',
        colleageName:'',
        admissionSchemeNumber:[],
        describeText:'',
        id:'',
      },
        options: [],
        major:'',
        id:'',
    }
  },
   mounted() {
    this.id=localStorage.getItem('id')
    this.getTableListApi()
    this.getmajor()
    this.editList()
  },
  methods: {
      async editList(){
         let res=await recruitInfo({id:this.id})
         console.log('23445',res)
         this.formInline.colleageName=res.data.colleageName
         this.formInline.beginTime=res.data.beginTime
         this.formInline.cityCode=res.data.cityCode
         this.formInline.countyCode=res.data.countyCode
         this.formInline.endTime=res.data.endTime
         this.formInline.describeText=res.data.describeText
         this.formInline.site=res.data.site
         this.formInline.id=res.data.id
         this.formInline.admissionSchemeNumber=res.data.admissionSchemeNumber

      },
    async getmajor(){
      let res=await majorListApi()
      this.major=res.rows
      console.log('44',res)
      console.log('33333',this.major)
    },
     async getTableListApi() {
       let res=await getTableApi()
       console.log('222',res)
       this.options=res.rows
        
    },
        //取消
    out(){
this.$router.push('/recruitstudents/Enrollmentplan')
    },
    //修改
   async edit(){
      let res=await recruitEdit(this.formInline)
      console.log('234',res)
      this.$message.success("修改成功"); 
       this.$router.push('/recruitstudents/Enrollmentplan')
    },
     addOut() {
      this.formInline.admissionSchemeNumber.push({majorId:this.major,studentNumber:''});
    },

    onSubmit() {
      console.log('submit!');
    }
  }
}
</script>

<style lang="scss" scoped>
.newpage {
  width: 100%;
  height: 100%;
  box-sizing: border-box;
  padding: 0 20px 20px;
  display: flex;
  // flex-direction: column;

  .content {
    flex: 1;
    background-color: white;
    border-radius: 10px 10px;
    min-width: 150vh;

    .topBox {
      padding: 60px;

      span {
        display: block;
        font-size: 14px;
      }

      .createTime {
        margin-left: 90px;
      }

      .first {

        .collegeName,
        .createTime {
          display: inline-block;
        }

        .block {
          display: inline-block;
        }
      }

      .second {
        margin-top: 30px;

        .collegeName,
        .createTime {
          vertical-align: top;
          display: inline-block;
        }
      }

      .plannedEnrollment {
        ul {
          // width: 100%;

          li {
            display: inline-block;
            width: 45%;
            margin: 10px 0;

            ::v-deep .el-input__inner {
              height: 26px;

            }

            ::v-deep .el-input__icon {
              line-height: 30px;
            }

            .number {
              margin: 0 15px;
              border: none;
            }

            .counts {
              // width: 50px;
              margin: 0 10px;
            }

            .countInp {
              display: inline-block;

              ::v-deep .el-input {
                width: 90px;
              }
            }

            i {
              margin-left: 10px;
              color: #ccc;
              font-size: 18px;
            }

          }

        }

        span {
          display: inline-block;
          margin: 25px 0 15px 5px;
        }

        .el-button {
          width: 400px;
          height: 36px;
          /* line-height: 30px; */
          border: 1px dashed #ccc;
          margin-left: 35px;
          text-align: center;
        }
      }


    }

    .btn {
      width: 400px;
      text-align: center;
      margin-left: 30px;
      margin-bottom: 30px;

      .el-button {
        margin-left: 30px;
      }
    }
  }

}
</style>
